<template>
  <el-cascader
    separator="-"
    :value="value"
    :props="defaultProp"
    :options="options"
    @change="handleChange"
  >
  </el-cascader>
</template>

<script>
import { getdepartment } from '@/api/department'
import { arrTree } from '@/utils/index'
export default {
  props: {
    value:{
      type: '',
      required: true
    } 
  },
  data() {
    return {
      defaultProp:{
        value: 'id',
        label: 'name'
      },
      options: []
    }
  },
  created() {
    this.getDepartment()
  },
  methods: {
    async getDepartment() {
      const res = await getdepartment() 
      // console.log(res)
      this.options = arrTree(res.data, 0)
    },
    handleChange(value) {
      // console.log(value)
      const id = value[value.length - 1]
      this.$emit('input', id)
    }
  }  
}

</script>

<style>

</style>